package br.pucrio.inf.validation;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.xtext.validation.Check;

import br.pucrio.inf.tamdera.ConceptDeclaration;
import br.pucrio.inf.tamdera.Paragraph;
import br.pucrio.inf.tamdera.RulesSpecification;
import br.pucrio.inf.tamdera.TamderaException;
 

public class TamderaJavaValidator extends AbstractTamderaJavaValidator {

//	@Check
//	public void checkGreetingStartsWithCapital(Greeting greeting) {
//		if (!Character.isUpperCase(greeting.getName().charAt(0))) {
//			warning("Name should start with a capital", MyDslPackage.Literals.GREETING__NAME);
//		}
//	}
	
	@Check
	public static void checkUniqueNamesOfConcepts (RulesSpecification rule )
	 throws TamderaException 
	 {
		List<String> toCompare = new ArrayList<String>();
		for (Paragraph paragraph : rule.getParagraphs() )
		{
			if (paragraph instanceof ConceptDeclaration) 
			{
				ConceptDeclaration decl = (ConceptDeclaration) paragraph;
				String name = decl.getName();
				if (!toCompare.contains( name ))
				{
					toCompare.add( name );
				}
				else 
				{
					throw new TamderaException( "The name " + name + " is used in more the one concept declaration" );
				}
			}
		}
	}
}
